<?php

/**
 * Desc
 * @description Holp You Do Good But Not Evil
 * @copyright   Copyright 2014-2015 <ycchen@iwshop.cn>
 * @license     LGPL (http://www.gnu.org/licenses/lgpl.html)
 * @author      Chenyong Cai <ycchen@iwshop.cn>
 * @package     Wshop
 * @link        http://www.iwshop.cn
 */

class iWechat extends Controller {
    
    public function __construct($ControllerName, $Action, $QueryString) {
        parent::__construct($ControllerName, $Action, $QueryString);
    }
    
    public function index(){
        
    }
    
    public function request_info_token($Query)
    {
        $redirect_uri = $this->uri;

        $code = WechatSdk::getAccessCode($redirect_uri, "snsapi_userinfo");
        if (FALSE == $code) {
            echo 'Failed to get access code';
            exit(0);
        }
        $token = WechatSdk::getAccessToken($code);
        
        if (!$token->access_token) {
            echo 'Failed to get access token';
            exit(0);
        } else {
            $this->sCookie('uinfoaccesstoken', $token->access_token, $token->expires);
            $ret_url = urldecode($Query->ret_url);
            error_log('redirect to:'.$ret_url);
            header("location:" . $ret_url);
        }
    }
    
}
